//
//  PACellHomePage.m
//  PAMobileWallet
//
//  Created by shen pu on 13-7-14.
//  Copyright (c) 2013年 Say_smp002. All rights reserved.
//

#import "PACellHomePage.h"
#import "PATimeLineInfo.h"
#import "PAAsynImageView.h"

#import <QuartzCore/QuartzCore.h>

@implementation PACellHomePage
@synthesize photoImageView;
@synthesize personalNameLable;
@synthesize dataTimeLable;
@synthesize moneyNumLable;
@synthesize addOrCutImage;
//@synthesize tradeRecordsImage;
@synthesize tradeRecordsBT;
@synthesize whiteSycleBgIV          = _whiteSycleBgIV;

#define DefaultHeadFrame CGRectMake(25, 11, 74, 74 )
#define ClientHeadFrame CGRectMake(31,14,62,62)

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.frame = CGRectMake(0, 0, 320, 239/2 - 20);
        CGRect framSize = self.frame;
        
        CGFloat x, y, w, h;
        CGSize size = framSize.size;
        
        x = 50/2;  y = 30/2-4;  w = 148/2;  h = 148/2;
        
        self.whiteSycleBgIV = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        self.whiteSycleBgIV.backgroundColor = [UIColor clearColor];
        self.whiteSycleBgIV.image = [UIImage imageNamed:@"home_face.png"];
        [self addSubview:self.whiteSycleBgIV];
        
        photoImageView = [[PAAsynImageView alloc] initWithFrame:CGRectMake(x+7 , y+4, w-14, h-14)];
        photoImageView.defaultImg = [UIImage imageNamed:@"home_photo.png"];
        photoImageView.backgroundColor = [UIColor clearColor];
        photoImageView.cornerRadius = (h-14)/2;
        [self addSubview:photoImageView];
        
        x = 60/2;  y = (30+86+10)/2;  w = 86/2;  h = 60/2;
        personalNameLable = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        personalNameLable.backgroundColor = [UIColor clearColor];
        personalNameLable.text = @"张三";
        personalNameLable.textAlignment = NSTextAlignmentCenter;
        personalNameLable.adjustsFontSizeToFitWidth = YES;
        [personalNameLable setFont:[UIFont systemFontOfSize:15.0]];
        [self addSubview:personalNameLable];
            
        x = size.width - 100;  y = 0;  w = 100;  h = 60/2;
        dataTimeLable = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        dataTimeLable.backgroundColor = [UIColor clearColor];
        dataTimeLable.text = @"2013-6-20";
        dataTimeLable.textColor = [UIColor grayColor];
        [dataTimeLable setFont:[UIFont systemFontOfSize:14.0]];
        [self addSubview:dataTimeLable];

        x = 366/2 - 20;  y = 10 + (86 - 35)/2;  w = 48/2;  h = 35/2;
        addOrCutImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        //addOrCutImage.image = [UIImage imageNamed:@"home_add.png"];
        [self addSubview:addOrCutImage];
        
        x = (366+48)/2 - 16;  y = 10 + (86 - 48)/2;  w = 200/2+7;  h = 48/2;
        moneyNumLable = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        moneyNumLable.textColor = [UIColor orangeColor];
        moneyNumLable.textAlignment = NSTextAlignmentCenter;
        moneyNumLable.backgroundColor = [UIColor clearColor];
        moneyNumLable.text = @"260";
        moneyNumLable.font = [UIFont systemFontOfSize:18.0];
        [self addSubview:moneyNumLable];
        
        x = (366+48+120)/2+8;  y = 10 + (86 - 48)/2;  w = 30/2;  h = 48/2;
        markYuanLable = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        markYuanLable.textAlignment = NSTextAlignmentRight;
        markYuanLable.backgroundColor = [UIColor clearColor];
        markYuanLable.font = [UIFont systemFontOfSize:15.0];
        markYuanLable.text = @"元";
        [self addSubview:markYuanLable];

        /*
        tradeRecordsImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        tradeRecordsImage.image = [UIImage imageNamed:@"home_payStation.png"];
        [self addSubview:tradeRecordsImage];
        */
        
        x = 366/2;  y = (20+86+10+20)/2;  w = 190/2;  h = 40/2;
        tradeRecordsBT = [UIButton buttonWithType:UIButtonTypeCustom];
        tradeRecordsBT.backgroundColor = [UIColor clearColor];
//        [tradeRecordsBT setBackgroundImage:[UIImage imageNamed:@"pay_situation_bg.png"] forState:UIControlStateNormal];
        tradeRecordsBT.titleLabel.font = [UIFont systemFontOfSize:14.0];
        tradeRecordsBT.frame = CGRectMake(x, y, w, h);
        tradeRecordsBT.enabled = NO;
        [self addSubview:tradeRecordsBT];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

}
- (void)loadInfo:(PATimeLineInfo *)info
{
    self.personalNameLable.text = info.targetInfo.realName;
    
    [self.photoImageView setImgUrl:info.targetInfo.headImageUrl key:info.targetInfo.phoneNum digest:info.targetInfo.headImageDigest];

    NSArray *dateArr_ = [info.updateDateStr componentsSeparatedByString:@" "];
    if ([dateArr_ count] > 1) {
        self.dataTimeLable.text = [dateArr_ objectAtIndex:0];
    }
    
    self.moneyNumLable.text = [NSString stringWithFormat:@"%.2f",info.lastTradeAmount];
    switch (info.lastTradeDirection) {
        case TDT_Out:{
            self.addOrCutImage.image = [UIImage imageNamed:@"home_delete.png"];
        }break;
        default:{
            self.addOrCutImage.image = [UIImage imageNamed:@"home_add.png"];
        }break;
    }
    switch (info.lastTradeStatus) {
        case TST_Success:{
            [self.tradeRecordsBT setTitle:@"交易成功" forState:UIControlStateNormal];
            [tradeRecordsBT setBackgroundImage:[UIImage imageNamed:@"pay_situation_bg.png"] forState:UIControlStateNormal];
        }break;
        case TST_Failed:{
            [self.tradeRecordsBT setTitle:@"交易关闭" forState:UIControlStateNormal];
            [self.tradeRecordsBT setBackgroundImage:[UIImage imageNamed:@"home_payStation.png"] forState:UIControlStateNormal];
        }break;
        case TST_WaitAccept:{
            [self.tradeRecordsBT setTitle:@"等待对方收款" forState:UIControlStateNormal];
            [self.tradeRecordsBT setBackgroundImage:[UIImage imageNamed:@"home_payStation.png"] forState:UIControlStateNormal];
        }break;
        default:break;
    }
    switch (info.targetInfo.accountStatus) {
        case AST_Quit_Account:
        case AST_Register_Step1_Account:
        case AST_UnRegister_Account:{
            self.personalNameLable.frame = CGRectMake(14, 88, 75, 30);
            self.personalNameLable.text = info.targetInfo.phoneNum;
            self.whiteSycleBgIV.hidden = YES;
            self.photoImageView.frame = DefaultHeadFrame;
        }break;
        default:{
            /*
             *  打断点跟到的的frame
             */
            self.personalNameLable.frame = CGRectMake(30, 88, 43, 30);
            self.personalNameLable.text = info.targetInfo.realName;
            self.whiteSycleBgIV.hidden = NO;
            self.photoImageView.frame = ClientHeadFrame;
        }break;
    }
    self.photoImageView.layer.cornerRadius = self.photoImageView.frame.size.height/2;
    CGPoint center = self.personalNameLable.center;
    center.x = self.photoImageView.center.x;
    self.personalNameLable.center = center;
    
}

@end
